package com.ruoyi.yey.student;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.yey.student.model.StudentSelectModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class StudentService extends ServiceImpl<StudentMapper, StudentEntity> {


    /**
     * 分页+模糊查询
     * @param page
     * @param searchModel
     * @return
     */
    public Page<Map> findAllByPage(Page page, StudentEntity searchModel) {


            return baseMapper.findBySearchVo(page,searchModel);


    }

    public List<Map> findAllByList(StudentEntity searchModel) {
        List<Map> studentList = baseMapper.findBySearchVo(searchModel);
        return studentList;
    }

    /**
     * 根据班级id查找学生列表
     * @param classId
     * @return
     */
    public List<StudentSelectModel> findAllByClassId(int classId) {
        List<StudentSelectModel> studentList =
                baseMapper.findAllByClassId(classId);
        return studentList;
    }

    public List<StudentSelectModel> sysStudentFindBystuName(String stuName) {
        List<StudentSelectModel> studentList =
                baseMapper.sysStudentFindBystuName(stuName);
        return studentList;
    }




    /**
     * 新增操作
     * @param student
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(StudentEntity student) {
        baseMapper.insert(student);
    }

    public StudentEntity findById(int id){
        return  baseMapper.selectById(id);
    }


    @Transactional(rollbackFor = Exception.class)
    public void edit(StudentEntity student){
         baseMapper.updateById(student);
    }

    @Transactional(rollbackFor = Exception.class)
    public void delByIds(int id) {
            baseMapper.deleteById(id);
    }


    /**
     * 获取学生列表, 用于导出
     * @return
     */
    public List<StudentSelectModel> findStuList() {


            return baseMapper.findStuList();


    }

    public StudentSelectModel findStudentById(int studentId){
        return baseMapper.findStudentById(studentId);

    }



}
